﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="物料品种管理.aspx.cs" Inherits="syc.Jidong.物料品种管理" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Configuration" %>
<script runat="server">
    
    protected void Button_PanDian_Click(object sender, EventArgs e)
    {
        string part1 =
@"<html xmlns:o='urn:schemas-microsoft-com:office:office'
xmlns:x='urn:schemas-microsoft-com:office:excel'
xmlns='http://www.w3.org/TR/REC-html40'>
<head>
<meta http-equiv=Content-Type content='text/html; charset=utf-8'>
<style>
<!--table
@page
{mso-header-data:;
mso-footer-data:;
margin:.79in .31in .79in .31in;
mso-header-margin:.51in;
mso-footer-margin:.51in;
/*mso-page-orientation:landscape;*/
mso-horizontal-page-align:center;
}
-->
</style>
<!--[if gte mso 9]><xml>
 <x:ExcelWorkbook>
  <x:ExcelWorksheets>
   <x:ExcelWorksheet>
    <x:Name>物料盘点表</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:Print>
      <x:ValidPrinterInfo/>
      <x:Scale>100</x:Scale>
      <x:PaperSizeIndex>9</x:PaperSizeIndex>
      <x:HorizontalResolution>200</x:HorizontalResolution>
      <x:VerticalResolution>200</x:VerticalResolution>
     </x:Print>
     <x:Selected/>
     <x:Panes>
      <x:Pane>
       <x:Number>3</x:Number>
       <x:ActiveRow>0</x:ActiveRow>
       <x:ActiveCol>0</x:ActiveCol>
      </x:Pane>
     </x:Panes>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
 </x:ExcelWorkbook>
</xml><![endif]-->
</head>
<body>
<style>
td{text-align:center;font-size:10pt;border:.5pt solid black;white-space:nowrap;	mso-text-control:shrinktofit;}
</style>
<table border=0 cellpadding=0 style=border-collapse:collapse>
<tr>
<td height=30 colspan=7 style=font-size:14pt;><b>物料盘点表</b></td>
</tr>
<tr>
<td width=100>编码</td>
<td width=150>品名</td>
<td width=120>型号/规格</td>
<td width=80>单位</td>
<td width=80>账面库存</td>
<td width=80>实有库存</td>
<td width=60>盈亏</td>
</tr>";


        SqlConnection Conn = new SqlConnection();
        Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
        Conn.Open();
        SqlCommand Cmd = new SqlCommand();
        Cmd.Connection = Conn;
        Cmd.CommandText = this.SqlText.Text.Replace("ID,FID", "ID,cast(isnull(dbo.材料盘点(ID),0) as float) as 库存,FID");
        SqlDataReader Reader = Cmd.ExecuteReader();

        Response.Charset = "utf-8";
        Response.ContentEncoding = System.Text.Encoding.UTF8;
        Response.ContentType = "application/ms-excel";
        Response.AddHeader("content-disposition", "attachment; filename=\"" + Server.UrlEncode("物料品种编码") + ".xls\"");
        int n = 3;
        Response.Write(part1);
        while (Reader.Read())
        {
            Response.Write("<tr><td style=\"mso-number-format:'\\@'\">" + ((int)Reader["ID"]).ToString("D10") + "</td>");
            Response.Write("<td>" + (string)Reader["品名"] + "</td>");
            Response.Write("<td>" + (string)Reader["规格"] + "</td>");
            Response.Write("<td>" + (string)Reader["单位"] + "</td>");
            Response.Write("<td>" + ((double)Reader["库存"]).ToString() + "</td>");
            Response.Write("<td></td><td x:num x:fmla='=F"+n+"-E"+n+"'></td></tr>");
            n++;
        }
        Reader.Close();
        Conn.Close();
        Reader.Dispose();
        Cmd.Dispose();
        Conn.Dispose();

        Response.Write("</table></body></html>");
        Response.End();
    }    
    
</script>
<html>
<head>
<title></title>
<link href="/TreeView/TreeView.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" language="javascript" src="/TreeView/TreeView.js"></script>
</head>
<body>
<script type="text/javascript" language="javascript" src="/common.js"></script>
<form id="form1" runat="server">
<asp:Label ID="SqlText" runat="server" Text="" Visible="false"></asp:Label>
<asp:Label ID="Label_FID" runat="server" Text="" Visible="false"></asp:Label>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
ConnectionString="<%$ ConnectionStrings:SCMConnectionString1 %>"
onselected="SqlDataSource1_Selected" 
 DeleteCommand="delete from 物料品种 where id=@id;"
>
<SelectParameters>
<asp:Parameter Name="库存价值" DbType="Double" Size="9" Direction="Output" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="ID" DbType="Int32" Size="4"/>
</DeleteParameters>
</asp:SqlDataSource>

<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
ConnectionString="<%$ ConnectionStrings:SCMConnectionString1 %>"
DeleteCommand="if not exists(select ID from 物料分类 where FID=@ID) and not exists(select ID from 物料品种 where FID=@ID) begin delete from 物料分类 where id=@ID end"
>
<DeleteParameters>
<asp:ControlParameter Name="ID" DbType="Int32" Size="4" ControlID="Label_FID"/>
</DeleteParameters>
</asp:SqlDataSource>

<div id="wintop" class="wintop">物料品种管理</div>

<div class="gridframe">
<div class="gridview">
    <table id="mt" border="1" width="100%" cellspacing="0" cellpadding="0" bordercolor="#e5cfab">
        <tr>
            <td class="grid-title" colspan="3">
                <div style="float:left"><asp:Button ID="Button_Mode" runat="server" Text="品种查询" CssClass="mbutton" 
                        UseSubmitBehavior="False" onclick="Button_Mode_Click"/><span style="margin-left:140px;"></span>物料品种列表
                    <span style="margin-left:20px;font-weight:normal;">日期：</span><asp:TextBox 
                        ID="Date1" runat="server" CssClass="textbox" Width="105px" 
                        AutoPostBack="True" ontextchanged="Date1_TextChanged" ></asp:TextBox><img alt="" src="/Icons/29.png"
                    align="middle" onclick="makecalendar(document.getElementById('Date1').value, document.getElementById('Date1'));" />
                </div>
                <div style="float:right">
                    <input id="Button_New" type="button" value="新增品种" class="mbutton" />
                    <asp:Button ID="Button_Edit" runat="server" Text="修 改" CssClass="mbutton" UseSubmitBehavior="False"/>
                    <asp:Button ID="Button_Delete" runat="server" Text="删 除" CssClass="mbutton"  
                        UseSubmitBehavior="False" 
                        OnClientClick="if(!confirm('增加或删除品种需慎重，若无必要请不要随意增加或删除品种\n确认要删除该条记录吗？'))return(false);" 
                        onclick="Button_Delete_Click" />
                    <asp:Button ID="Button_Export" runat="server" Text="导出编码表.." 
                        CssClass="mbutton2" UseSubmitBehavior="False" onclick="Button_Export_Click"/>
                    <asp:Button ID="Button_PanDian" runat="server" Text="导出盘点表.." 
                        CssClass="mbutton2" UseSubmitBehavior="False" 
                        onclick="Button_PanDian_Click"/>
                </div>
            </td>
        </tr>
        <tr>
	        <td class="grid-back" style="background-color:#ffffff;" width="200">
	            <div style="height:26px;text-align:center;font-size:14px;color:#6f320a;padding:4px 2px 4px 4px;">
	                <div style="float:left;padding-top:2px;"><b>分类目录</b></div>
                    <div style="float:right"><asp:Button ID="Button_Ed" runat="server" Text="=编辑" CssClass="mbutton40" ToolTip="修改当前分类名称" /><asp:Button ID="Button_Del" runat="server" Text="-删除" CssClass="mbutton40" ToolTip="删除当前分类"
                    OnClientClick="if(!confirm('确认要删除当前分类吗？'))return(false);" 
                            onclick="Button_Del_Click" /><asp:Button ID="Button_Add" runat="server" Text="+子类" CssClass="mbutton40" ToolTip="在当前分类下增加子分类" /></div>
	            </div>
	            <div id="MyTree" style=" background-color:#ffffff;overflow:scroll;text-align:left;"></div>
	        </td>
	        <td class="grid-back" style="background-color:#ffffff;font-size:14px;color:#6f320a;" width="200">
	            <div style="height:26px;text-align:center;padding-top:4px;font-size:14px;color:#6f320a;"><b>品种查询</b></div>
	            <div style="padding:5px;">
                    编码：<asp:TextBox ID="BianMa" runat="server" CssClass="textbox" Width="120"></asp:TextBox><br />
        	                    
                    品名：<asp:TextBox ID="PinMing" runat="server" CssClass="textbox" Width="120"></asp:TextBox><br />

                    规格：<asp:TextBox ID="GuiGe" runat="server" CssClass="textbox" Width="120"></asp:TextBox><br />

                    简码：<asp:TextBox ID="JianMa" runat="server" CssClass="textbox" Width="120"></asp:TextBox><br />

                    权重：<asp:TextBox ID="QuanZhong" runat="server" CssClass="textbox" Width="120"></asp:TextBox><br />
                    <div style="text-align:center;margin-top:5px;">
                        <asp:Button ID="Button_Query" runat="server" Text="查 询" UseSubmitBehavior="false" 
                                CssClass="mbutton" onclick="Button_Query_Click" />
                        <asp:Button ID="Button_Reset" runat="server" Text="清空条件" UseSubmitBehavior="false" 
                                CssClass="mbutton" onclick="Button_Reset_Click" />
                    </div>
                </div>
	        </td>
            <td class="grid-back">
                <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
                    AutoGenerateColumns="False" CssClass="grid" DataKeyNames="ID" 
                    DataSourceID="SqlDataSource1"
                    PageSize="20"
                    GridLines="None" ondatabound="GridView1_DataBound" 
                    onpageindexchanged="GridView1_PageIndexChanged" AllowSorting="True" 
                    UseAccessibleHeader="False" 
                    onselectedindexchanged="GridView1_SelectedIndexChanged">
                    <PagerSettings Visible="False" />
                    <RowStyle CssClass="grid-row-normal" />
                    <Columns>
                        <asp:TemplateField HeaderText="">
                            <ItemTemplate>
                                <asp:Button ID="Button_xz" runat="server" CommandName="Select" Text="选择" CssClass="hide"/>
                                <img src="/Icons/online.gif" style="margin-top:2px;" alt="" />
                            </ItemTemplate>
                            <HeaderStyle CssClass="grid-header" />
                            <ItemStyle CssClass="grid" HorizontalAlign="Center" Width="20px" />
                        </asp:TemplateField>
                        
                        <asp:TemplateField HeaderText="分类编码">
                            <ItemTemplate>
                                <asp:Label ID="Label_flbm" runat="server" Text='<%# Eval("FID","{0:D7}") %>'></asp:Label>
                            </ItemTemplate>
                            <HeaderStyle CssClass="grid-header" />
                            <ItemStyle CssClass="grid" HorizontalAlign="Center" Width="60px" />
                        </asp:TemplateField>

                        <asp:TemplateField HeaderText="编码">
                            <ItemTemplate>
                                <asp:Label ID="Label_bm" runat="server" Text='<%# Eval("ID","{0:D10}") %>'></asp:Label>
                            </ItemTemplate>
                            <HeaderStyle CssClass="grid-header" />
                            <ItemStyle CssClass="grid" HorizontalAlign="Center" Width="80px" />
                        </asp:TemplateField>
                                              
                        <asp:TemplateField HeaderText="品名" SortExpression="品名">
                            <ItemTemplate>
                                <asp:Label ID="Label_pm" runat="server" Text='<%# Eval("品名") %>'></asp:Label>
                            </ItemTemplate>
                            <HeaderStyle CssClass="grid-header" />
                            <ItemStyle CssClass="grid" HorizontalAlign="Left" Width="120px" />
                        </asp:TemplateField>
                        
                        <asp:TemplateField HeaderText="型号/规格">
                            <ItemTemplate>
                                <asp:Label ID="Label_gg" runat="server" Text='<%# Eval("规格") %>'></asp:Label>
                            </ItemTemplate>
                            <HeaderStyle CssClass="grid-header" />
                            <ItemStyle CssClass="grid" HorizontalAlign="Left" Width="120px" />
                        </asp:TemplateField>
                        
                        <asp:TemplateField HeaderText="单位">
                            <ItemTemplate>
                                <asp:Label ID="Label_dw" runat="server" Text='<%# Eval("单位") %>'></asp:Label>
                            </ItemTemplate>
                            <HeaderStyle CssClass="grid-header" />
                            <ItemStyle CssClass="grid" HorizontalAlign="Center" Width="80px" />
                        </asp:TemplateField>
                        
                        <asp:TemplateField HeaderText="单价(元)" SortExpression="单价">
                            <ItemTemplate>
                                <asp:Label ID="Label_dj" runat="server" Text='<%# Eval("单价") %>'></asp:Label>
                            </ItemTemplate>
                            <HeaderStyle CssClass="grid-header" />
                            <ItemStyle CssClass="grid" HorizontalAlign="Center" Width="80px" />
                        </asp:TemplateField>
                        
                        <asp:TemplateField HeaderText="简码">
                            <ItemTemplate>
                                <asp:Label ID="Label_jm" runat="server" Text='<%# Eval("简码") %>'></asp:Label>
                            </ItemTemplate>
                            <HeaderStyle CssClass="grid-header" />
                            <ItemStyle CssClass="grid" HorizontalAlign="Center" Width="80px" />
                        </asp:TemplateField>
                        
                        <asp:TemplateField HeaderText="权重" SortExpression="权重">
                            <ItemTemplate>
                                <asp:Label ID="Label_qz" runat="server" Text='<%# Eval("权重") %>'></asp:Label>
                            </ItemTemplate>
                            <HeaderStyle CssClass="grid-header" />
                            <ItemStyle CssClass="grid" HorizontalAlign="Center" Width="50px" />
                        </asp:TemplateField>
                    </Columns>
                    <SelectedRowStyle CssClass="grid-row-selected" />
                  </asp:GridView>
            </td>
        </tr>
        <tr>
            <td colspan="3">
                <table width="100%">
                    <tr>
                        <td class="pagebar">
                            <asp:Button ID="Button_Pager_First" UseSubmitBehavior="false" runat="server" Text="" ToolTip="首页" 
                                CssClass="pageturn-first-b" onclick="Pager_Click" CommandName="--" />
                            <asp:Button ID="Button_Pager_Prev" UseSubmitBehavior="false" runat="server" Text="" ToolTip="上一页" 
                                CssClass="pageturn-prev-b" onclick="Pager_Click" CommandName="-" />
                            <input type="button" class="page-split" UseSubmitBehavior="false" disabled />第<asp:TextBox 
                                ID="TextBox_Pager" AutoPostBack="True" runat="server" CssClass="pageturn" 
                                ontextchanged="Pager_Click"></asp:TextBox>页<input type="button" class="page-split" disabled /><asp:Label ID="Label_Pages" UseSubmitBehavior="false" runat="server"></asp:Label><input type="button" class="page-split" disabled />
                            
                            <asp:Button ID="Button_Pager_Next" UseSubmitBehavior="false" runat="server" Text="" ToolTip="下一页" 
                                CssClass="pageturn-next-b" onclick="Pager_Click" CommandName="+" />
                            <asp:Button ID="Button_Pager_Last" UseSubmitBehavior="false" runat="server" Text="" ToolTip="末页" 
                                CssClass="pageturn-last-b" onclick="Pager_Click" CommandName="++" /><asp:Label ID="Label9" runat="server"></asp:Label><input type="button" class="page-split" disabled />
                        </td>
                        <td class="pagebar" align="right">
                            <asp:Label ID="Label_Total" runat="server"></asp:Label>
                        </td>
                    </tr>
               </table>

            </td>
        </tr>
    </table>
    
</div>
</div>

</form>
<script>
    var notice = '<%=this.Notice %>';
    if (notice != '') {
        parent.showmsgbox(notice);
    }
</script>
<script>
    var textboxs = document.getElementsByTagName("input");
    var i;
    for (i = 0; i < textboxs.length; i++) {
        if (textboxs[i].className == "textbox") {
            //textboxs[i].onchange = function(e) { this.className = "textbox-changed"; };
            textboxs[i].onfocus = function(e) { this.select(); };
        }
        else if (textboxs[i].className == "pageturn" || textboxs[i].className == "intxt1" || textboxs[i].className == "intxt2") {
            textboxs[i].onfocus = function(e) { this.select(); };
        }
    }
    var rows = document.getElementsByTagName("tr");
    for (i = 0; i < rows.length; i++) {

        if (rows[i].className == "grid-row-normal") {
            rows[i].onmouseover = function() { this.className = "grid-row-bright"; };
            rows[i].onmouseout = function() { this.className = "grid-row-normal"; };
            rows[i].onclick = selectRow;
        }
    }

    document.onkeydown = function(e) {
        if (!e) e = window.event;
        var tag = e.srcElement;
        if (!tag) tag = e.target;
        if (tag.tagName == "INPUT" && tag.className == "textbox" || tag.tagName == "SELECT") {
            if (e.keyCode == 13) e.keyCode = 9;
        }
    }
    
    var mt = document.getElementById("mt");
    if (document.getElementById("Button_Mode").value == "品种查询") {
        mt.rows[1].cells[1].style.display = "none";
    }
    else {
        mt.rows[1].cells[0].style.display = "none";
    }
    
    
    TreeView_Href = "/Store/物料分类查询.ashx?s=";
    TreeView_Action="/Store/物料品种管理.aspx?fid=";
    TreeView_Create("MyTree", "0000000", "物料中心", "/TreeView/home.png");
    var fid = "<%=this.Label_FID.Text %>";
    var ca=document.getElementById(fid).firstChild.lastChild;
    ca.className = "cnode";

    document.getElementById("Button_Ed").onclick = function() {
    parent.swin2_load('/Store/物料分类编辑.aspx?cmd=ed&id=' + fid, 400, 250);
    };
    document.getElementById("Button_Add").onclick = function() {
        parent.swin2_load('/Store/物料分类编辑.aspx?cmd=in&id=' + fid, 400, 250);
    };
    document.getElementById("Button_New").onclick = function() {
        parent.swin2_load('/Store/物料品种录入.aspx?fid=' + fid, 560, 300);
    };

    <%=this.Autorun %>
</script>
</body>
</html>
